package com.emser.unc.client.view;

import com.emser.unc.client.CloudMobile;
import com.emser.unc.client.presenter.ProductPopupPresenter;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;

public class ProductPopupView extends DialogBox implements ProductPopupPresenter.Display {
	private Label code, lblWTitleP;
	private TextBox title, price, stock;
	private Button btnSave, btnCancelar;
	private Label lblWPrice;
	private Label lblWStock;

	public ProductPopupView() {
		super(true);
	    setSize("474px", "200px");
	    FlexTable flexTable = new FlexTable();
	    flexTable.setSize("451px", "164px");
	    setWidget(flexTable);
	    
	    Label lblCode = new Label(CloudMobile.constants.code()+":");
	    flexTable.setWidget(0, 0, lblCode);	    
	    flexTable.getCellFormatter().setHeight(0, 0, "20px");
	    flexTable.getCellFormatter().setWidth(0, 0, "150px");
	    lblCode.setHeight("100%");
	    
	    code = new Label("");
	    flexTable.setWidget(0, 1, code);
	    flexTable.getCellFormatter().setHeight(0, 1, "20px");
	    flexTable.getCellFormatter().setWidth(0, 1, "200px");
	    code.setSize("95%", "100%");
	    
	    
	    Label lblTitle = new Label(CloudMobile.constants.title()+":");
	    flexTable.setWidget(1, 0, lblTitle);
	    flexTable.getCellFormatter().setHeight(1, 0, "20px");
	    flexTable.getCellFormatter().setWidth(1, 0, "150px");
	    
	    
	    title = new TextBox();
	    flexTable.setWidget(1, 1, title);
	    flexTable.getCellFormatter().setHeight(1, 1, "20px");
	    flexTable.getCellFormatter().setWidth(1, 1, "200px");
	    title.setSize("95%", "100%");
	    
	    lblWTitleP = new Label(CloudMobile.constants.wInvalidate());
	    lblWTitleP.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(1, 2, lblWTitleP);
	    flexTable.getCellFormatter().setHeight(1, 2, "20px");
	    flexTable.getCellFormatter().setWidth(1, 2, "130px");
	    lblWTitleP.setVisible(false);
	    
	    Label lblPrice = new Label(CloudMobile.constants.price()+":");
	    flexTable.setWidget(2, 0, lblPrice);
	    flexTable.getCellFormatter().setHeight(2, 0, "20px");
	    flexTable.getCellFormatter().setWidth(2, 0, "150px");
	    
	    
	    price = new TextBox();
	    flexTable.setWidget(2, 1, price);
	    flexTable.getCellFormatter().setHeight(2, 1, "20px");
	    flexTable.getCellFormatter().setWidth(2, 1, "200px");
	    price.setSize("95%", "100%");
	    
	    lblWPrice = new Label(CloudMobile.constants.wInvalidate());
	    lblWPrice.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(2, 2, lblWPrice);
	    lblWPrice.setSize("106", "16");
	    flexTable.getCellFormatter().setHeight(2, 2, "20px");
	    flexTable.getCellFormatter().setWidth(2, 2, "130px");
	    
	    Label lblStock = new Label(CloudMobile.constants.stock()+":");
	    flexTable.setWidget(3, 0, lblStock);
	    flexTable.getCellFormatter().setHeight(3, 0, "20px");
	    flexTable.getCellFormatter().setWidth(3, 0, "150px");
	    
	    
	    stock = new TextBox();
	    flexTable.setWidget(3, 1, stock);
	    flexTable.getCellFormatter().setHeight(3, 1, "20px");
	    flexTable.getCellFormatter().setWidth(3, 1, "200px");
	    stock.setSize("95%", "100%");
	    
	    lblWStock = new Label(CloudMobile.constants.wInvalidate());
	    lblWStock.setStyleName("gwt-LblWarning");
	    flexTable.setWidget(3, 2, lblWStock);
	    lblWStock.setSize("106", "16");
	    flexTable.getCellFormatter().setHeight(3, 2, "20px");
	    flexTable.getCellFormatter().setWidth(3, 2, "130px");
	    
	    Grid grid = new Grid(1, 2);
	    flexTable.setWidget(4, 1, grid);
	    flexTable.getCellFormatter().setHeight(4, 1, "28px");
	    flexTable.getCellFormatter().setWidth(4, 1, "");
	    grid.setSize("210px", "28px");
	    btnCancelar = new Button(CloudMobile.constants.cancel());
	    grid.setWidget(0, 1, btnCancelar);
	    btnCancelar.setSize("100px", "28px");
	    
	    btnSave = new Button(CloudMobile.constants.save());
	    grid.setWidget(0, 0, btnSave);
	    btnSave.setSize("100px", "28px");
	    flexTable.getCellFormatter().setHorizontalAlignment(1, 2, HasHorizontalAlignment.ALIGN_CENTER);
	    flexTable.getCellFormatter().setVerticalAlignment(1, 2, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.getCellFormatter().setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_RIGHT);
	    flexTable.getCellFormatter().setVerticalAlignment(3, 0, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setHorizontalAlignment(2, 2, HasHorizontalAlignment.ALIGN_CENTER);
	    flexTable.getCellFormatter().setVerticalAlignment(2, 2, HasVerticalAlignment.ALIGN_MIDDLE);
	    flexTable.getCellFormatter().setHorizontalAlignment(3, 2, HasHorizontalAlignment.ALIGN_CENTER);
	    flexTable.getCellFormatter().setVerticalAlignment(3, 2, HasVerticalAlignment.ALIGN_MIDDLE);
	    setSize("350px", "150px");
	    setText(CloudMobile.constants.textPopUpW());
	    setGlassEnabled(true);
	    center();
	    show();
	}

	@Override
	public HasText getCode() {
		return code;
	}

	@Override
	public HasValue<String> getPrice() {
		return price;
	}

	@Override
	public HasValue<String> getStock() {
		return stock;
	}

	@Override
	public HasClickHandlers getSaveButton() {
		return btnSave;
	}

	@Override
	public HasValue<String> getTitleProduct() {
		return title;
	}
	@Override
	  public void hide() {
	    super.hide();
	  }

	@Override
	public void setTextPopup(String text) {
		setText(text);
		
	}

	@Override
	public String getTextPopup() {
		return getText();
	}

	@Override
	public void enableSave(boolean flag) {
		btnSave.setEnabled(false);	
	}

	@Override
	public HasClickHandlers getCancelButton() {
		return btnCancelar;
	}

	@Override
	public void setVisibeWTitle(boolean visible) {
		lblWTitleP.setVisible(visible);
		
	}

	@Override
	public void setVisibeWPrice(boolean visible) {
		lblWPrice.setVisible(visible);
		
	}

	@Override
	public void setVisibeWStock(boolean visible) {
		lblWStock.setVisible(visible);
		
	}

	

}
